<template>
<div class="login_containter">
    <div class="login_box">
        <!-- logo区域 -->
        <div class="png">
            <img src="../assets/logo.png" alt="头像">
        </div>
        <!-- 表单区域 -->
        <div>
            <el-form class="loginInfo" :model="ruleForm" :rules="rules" ref="loginFormRef">
                <!-- 用户名 -->
                <el-form-item  prop= "username">
                    <el-input prefix-icon="iconfont icon-user" v-model="ruleForm.username"></el-input>
                </el-form-item>
                <!-- 密码 -->
                <el-form-item  prop="password">
                    <el-input type="password" prefix-icon="iconfont icon-3702mima" v-model="ruleForm.password"></el-input>
                </el-form-item>
                <!--按钮 -->
                <el-form-item class="btn">
                  <button type="button" @click="login"> log in!</button>
                  <button type="button" @click="resetLoginInfo"> reset</button>
                  <!-- <el-button type="priamry" @click="login" >login in</el-button>
                  <el-button type="info" @click="resetLoginInfo" plain >clear</el-button> -->
                </el-form-item>
            </el-form>
        </div>
    </div>
</div>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        username: 'admin',
        password: '123456'
      },
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, max: 12, message: '长度在 6 到 12 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    resetLoginInfo() {
      this.$refs.loginFormRef.resetFields()
    },
    login() {
      this.$refs.loginFormRef.validate(async valid => {
        if (!valid) return
        // 将登陆者的数据发给后台
        const { data: res } = await this.$http.post('login', this.ruleForm)
        // 根据验证规则判断是否成功
        if (res.meta.status !== 200) return this.$message.error('登录失败')
        this.$message.success('登录成功')
        window.sessionStorage.setItem('token', res.data.token)
        // 跳转主页
        this.$router.push('/home')
      })
    }
  }
}
</script>

<style lang="less" scoped>
.login_containter{
    background-image: linear-gradient(to top, #fbc2eb 0%, #a6c1ee 100%);
    //background-color: aqua;
    height: 100%;
}
.login_box{
    background-image: linear-gradient(to top, #a8edea 0%, #fed6e3 100%);
    width: 450px;
    height: 300px;
    background-color: rgb(224, 229, 236);
    box-shadow: rgba(163, 177, 198, 0.5) 12px 12px 24px 0px, rgb(255, 255, 255) -12px -12px 24px 0px;
    -webkit-box-shadow: rgba(163, 177, 198, 0.5) 12px 12px 24px 0px, rgb(255, 255, 255) -12px -12px 24px 0px;
    border-radius: 40px;
    -webkit-border-radius: 40px;
    //background-color: white;
    //border-radius: 3px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform:translate(-50%, -50%);
    border-radius: 15px;
}
img{
    width: 100px;
    height: 100px;
    margin:  auto 175px;
}
.loginInfo{
    padding: 0 20px;
}
.btn{
    display: flex;
    justify-content: center;
}
button {
  margin-right: 15px;
 padding: 15px 25px;
 border: unset;
 border-radius: 15px;
 color: #212121;
 z-index: 1;
 background: #e8e8e8;
 position: relative;
 font-weight: 1000;
 font-size: 17px;
 -webkit-box-shadow: 4px 8px 19px -3px rgba(0,0,0,0.27);
 box-shadow: 4px 8px 19px -3px rgba(0,0,0,0.27);
 transition: all 250ms;
 overflow: hidden;
}

button::before {
 content: "";
 position: absolute;
 top: 0;
 left: 0;
 height: 100%;
 width: 0;
 border-radius: 15px;
 background-color: #212121;
 z-index: -1;
 -webkit-box-shadow: 4px 8px 19px -3px rgba(0,0,0,0.27);
 box-shadow: 4px 8px 19px -3px rgba(0,0,0,0.27);
 transition: all 250ms
}

button:hover {
 color: #e8e8e8;
}

button:hover::before {
 width: 100%;
}
</style>
